<template>
	<div>
		<div class="publicpageview" id="publicpageview">
			<div style="text-align: center;font-weight: bold;margin-top: 20px;">住宅房屋租金调整过程记录表</div>
			<div style="display:flex;margin-top: 10px;flex-flow: row wrap" v-if="topContet">
				<div style="margin-left: 30px;">产别{{topContet.field1}}</div>
				<div style="margin-left: 30px;">管片{{topContet.field2}}</div>
				<div style="margin-left: 30px;">地址{{topContet.field3}}</div>
				<div style="margin-left: 30px;">查询日期{{topContet.field4}}</div>
				<div style="margin-left: 30px;">调租日期{{topContet.field5}}</div>
			</div>
			<div style="display: flex;margin-top: 20px;box-sizing: border-box;">
				<div class="list3">门号</div>
				<div class="list3">间号</div>
				<div class="list3">用途</div>
				<div class="list3">单位分数</div>
				<div class="list3">分值</div>
				<div class="list3">单位租金</div>
				<div class="list3">面积合计</div>
				<div class="list3">居室面积</div>
				<div class="list3">附属面积</div>
				<div class="list3">附加面积</div>
				<div class="list3">租金合计</div>
				<div class="list3">居室租金</div>
				<div class="list3">附属租金</div>
				<div class="list3">附加租金</div>
			</div>
			<div style="display: flex;box-sizing: border-box;" v-for="(item,index) in list" :key="index">
				<div class="list3">{{item.fieldName1}}</div>
				<div class="list3">{{item.fieldName2}}</div>
				<div class="list3">{{item.fieldName3}}</div>
				<div class="list3">{{item.fieldName4}}</div>
				<div class="list3">{{item.fieldName5}}</div>
				<div class="list3">{{item.fieldName6}}</div>
				<div class="list3">{{item.fieldName7}}</div>
				<div class="list3">{{item.fieldName8}}</div>
				<div class="list3">{{item.fieldName9}}</div>
				<div class="list3">{{item.fieldName10}}</div>
				<div class="list3">{{item.fieldName11}}</div>
				<div class="list3">{{item.fieldName12}}</div>
				<div class="list3">{{item.fieldName13}}</div>
				<div class="list3">{{item.fieldName14}}</div>
			</div>
			<div style="display: flex;box-sizing: border-box;">
				<div class="list3">合计</div>
				<div class="list3"></div>
				<div class="list3"></div>
				<div class="list3"></div>
				<div class="list3"></div>
				<div class="list3"></div>
				<div class="list3">{{hejiObject.fieldName7}}</div>
				<div class="list3">{{hejiObject.fieldName8}}</div>
				<div class="list3">{{hejiObject.fieldName9}}</div>
				<div class="list3">{{hejiObject.fieldName10}}</div>
				<div class="list3">{{hejiObject.fieldName11}}</div>
				<div class="list3">{{hejiObject.fieldName12}}</div>
				<div class="list3">{{hejiObject.fieldName13}}</div>
				<div class="list3">{{hejiObject.fieldName14}}</div>
			</div>
		</div>
		<button style="margin: 10px auto 0;display: block;" @click="handleout">打印住宅房屋租金调整过程记录表</button>
	<!-- 	
		<button style="margin: 10px auto 0;display: block;" v-print="printObj">打印住宅房屋租金调整过程记录表</button>
		<div id="loading" v-show="printLoading"></div> -->
	</div>
</template>

<script>
	import * as XLSX from 'xlsx'
	import dayjs from 'dayjs'
	import {
		houseAdminList,
		addRoom,
		roomDetails,
		updRoom,
		blockList,
		blockDetail
	} from '@/api/industry'
	export default {
		props: {
			blockobj: Object
		},
		name: 'zujintiaozhengguocheng',
		data() {
			return {
				printLoading: true,
				printObj: {
					id: "publicpageview",
					popTitle: '打印预览',
					extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css",
					beforeOpenCallback(vue) {
						console.log('打开之前')
					},
					openCallback(vue) {
						console.log('执行了打印')
					},
					closeCallback(vue) {
						console.log('关闭了打印工具')
					}
				},
				list:[],
				topContet:{},
				hejiObject:{
					fieldName7:0,
					fieldName8:0,
					fieldName9:0,
					fieldName10:0,
					fieldName11:0,
					fieldName12:0,
					fieldName13:0,
					fieldName14:0
				}
			}
		},
		computed: {},
		mounted() { 
			console.log(this.blockobj)
			this.list = this.blockobj.export1List	
			this.topContet = this.blockobj.exportTou
			if(this.list){
				this.list.forEach((item,index)=>{
					this.hejiObject.fieldName7 = Number(this.hejiObject.fieldName7 )+Number(item.fieldName7)
					this.hejiObject.fieldName8 = Number(this.hejiObject.fieldName8 )+Number(item.fieldName8)
					this.hejiObject.fieldName9 = Number(this.hejiObject.fieldName9 )+Number(item.fieldName9)
					this.hejiObject.fieldName10 = Number(this.hejiObject.fieldName10 )+Number(item.fieldName10)
					this.hejiObject.fieldName11 = Number(this.hejiObject.fieldName11 )+Number(item.fieldName11)
					this.hejiObject.fieldName12 = Number(this.hejiObject.fieldName12 )+Number(item.fieldName12)
					this.hejiObject.fieldName13 = Number(this.hejiObject.fieldName13 )+Number(item.fieldName13)
					this.hejiObject.fieldName14 = Number(this.hejiObject.fieldName14 )+Number(item.fieldName14)
				})
			}
		},

		methods: {
			handleout() {
				this.$confirm('此操作将导出该条内容，请确认是否继续操作？', '导出提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				})
				.then(() => {
					let list = this.list
					let outList = []
					this.list.forEach((item, index) => {
						outList.push({
							门号: item.fieldName1,
							间号: item.fieldName2,
							用途: item.fieldName3,
							单位分数: item.fieldName4,
							分值: item.fieldName5,
							单位租金: item.fieldName6,
							面积合计: item.fieldName7,
							居室面积: item.fieldName8,
							附属面积: item.fieldName9,
							附加面积: item.fieldName10,
							租金合计: item.fieldName11,
							居室租金: item.fieldName12,
							附属租金: item.fieldName13,
							附加租金: item.fieldName14
						})
					})
					outList.push({
						门号: '合计',
						间号: '',
						用途: '',
						单位分数: '',
						分值: '',
						单位租金: '',
						面积合计: this.hejiObject.fieldName7,
						居室面积: this.hejiObject.fieldName8,
						附属面积: this.hejiObject.fieldName9,
						附加面积: this.hejiObject.fieldName10,
						租金合计: this.hejiObject.fieldName11,
						居室租金: this.hejiObject.fieldName12,
						附属租金: this.hejiObject.fieldName13,
						附加租金: this.hejiObject.fieldName14
					})
					// 获取表格数据
					const data = outList
					// 转换数据为工作表
					const worksheet = XLSX.utils.json_to_sheet(data)
					// 创建新的工作簿
					const workbook = XLSX.utils.book_new()
					// 将工作表添加到工作簿
					XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
					// 导出Excel文件
					XLSX.writeFile(workbook, '住宅房屋租金调整过程记录表.xlsx')
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消导出'
					})
				})
			}
		},
	}
</script>

<style scoped>
	.publicpageview {
		width: 1200px;
		height: auto;
		background-color: #fff;
		margin: 20px auto 0;
		overflow: hidden;
		box-sizing: border-box;
		padding: 10px;
		outline: 1px solid black;
	}

	.list1 {
		width: 100px;
		box-sizing: border-box;
		height: 30px;
		line-height: 30px;
		text-align: center;
		outline: 1px solid black;
	}

	.list2 {
		width: 50px;
		height: 30px;
		line-height: 30px;
		outline: 1px solid black;
		text-align: center;
	}

	.left {
		width: 25px;
		height: 360px;
		outline: 1px solid black;
		line-height: 180px;
		text-align: center;
		box-sizing: border-box;
	}

	.list3 {
		width: 120px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
		font-size: 12px
	}
</style>